/**
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2017，所有权利保留。
 * 
 * 项目名：	JustTest-0.0.1-SNAPSHOT
 * 文件名：	UpowerTest.java
 * 模块说明：	
 * 修改历史：
 * 2017年6月27日 - wangdanhua - 创建。
 */
package http.request;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import test.xyz.HttpRequest;
import test.xyz.HttpRequest.HttpRequestException;

/**
 * 鼎力云支付中心api-支付设备接入-接口测试
 * 
 * @author wangdanhua
 *
 */
public class UpowerTest {

  private static final String appKey = "F8tcK5Mlq66Kei7u75Fienc3E3vKMrsA";

  public static void main(String[] args)
      throws IllegalAccessException, InvocationTargetException, NoSuchMethodException,
      HttpRequestException, UnsupportedEncodingException, JsonProcessingException {

    OrderStateQueryParam param = new OrderStateQueryParam();
    param.setDevice_no("97261707344064");
    param.setDevice_source("paybox_i9000s");
    param.setNonce_str("YU5KqqUQxmjCblzD");
    param.setPp_trade_no("000100020003");

    String url = "http://139.129.92.1/paypp/ppPay/query";
    String url2 = "https://pay-test.qianfan123.com/paypp/ppPay/query";
    
    System.out.println(requestData(url2, param));

  }

  private static String requestData(String url, UpowerPayParam param)
      throws HttpRequestException, UnsupportedEncodingException, JsonProcessingException {
    String sign = PPPayServerUtil.buildRequestSign(param.getParams(), appKey);
    param.setSign(sign);

    HttpRequest httpRequest = HttpRequest.post(url).trustAllCerts().trustAllHosts()
        .contentType("application/json", "utf-8").accept("application/json;charset=utf-8")
        .send(new ObjectMapper().writeValueAsString(param).getBytes("utf-8"));

    if (!httpRequest.ok()) {
      throw new RuntimeException("请求出错:" + httpRequest.body());
    }
    String body = httpRequest.body();
    return body;
  }

}
